//
//  DFBaseNavController.swift
//  新浪微博
//
//  Created by dafei on 16/5/22.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class DFBaseNavController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        //解决右滑返回手势的问题
        //村早bug 在最顶级的页面  右滑返回手势还响应
        self.interactivePopGestureRecognizer?.delegate = self
        
    }
    //重写push方法
    //HMBaseNavController(rootViewController: vc) ==> 内部会进行push操作 ==> 压栈
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        //变量名称和方法  最好不要重写
        //判断时候顶级页面
        var backtitle = "返回"
        if childViewControllers.count > 0 {
        
            if childViewControllers.count == 1 {
            //设置返回按钮的title
            backtitle = childViewControllers.first?.title ?? "返回"
            }
            let back = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backtitle, target: self, action: #selector(popToFrontVC))
            viewController.navigationItem.leftBarButtonItem = back
        
        }
        super.pushViewController(viewController, animated: animated)
        
        
        
        
    }
    
    @objc private func popToFrontVC() {
    
        popViewControllerAnimated(true)
    }
    
    //实现手势协议
    //一般协议方法返回值 为 bool类型 表示 如果返回 true 就表示对象能够正常工作
    //如果返回fale 对象就不能正常工作
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
//        if childViewControllers.count > 1{
//        
//            //进入子页面
//            return true
//        
//        }
//        return false
        
        return childViewControllers.count > 1
    }
    
 

   

}
